import Vue from "vue";

import Cookies from "js-cookie";

import Element from "element-ui";
import "./assets/styles/element-variables.scss";
import "@/modules/directives.js"; //拖拽
import "element-ui/lib/theme-chalk/icon.css";
// import "element-ui/packages/theme-chalk/src/index";

import "xe-utils";
import VXETable from "vxe-table";
import "vxe-table/lib/style.css";
Vue.use(VXETable);
// import 'echarts-liquidfill/src/liquidFill.js'
// import 'echarts-liquidfill'

//通知栏
import Vant from "vant";
import "vant/lib/index.css";
Vue.use(Vant);

// 给 vue 实例挂载内部对象，例如：
Vue.prototype.$XModal = VXETable.modal;
Vue.prototype.$XPrint = VXETable.print;
Vue.prototype.$XSaveFile = VXETable.saveFile;
Vue.prototype.$XReadFile = VXETable.readFile;

import "@/assets/styles/index.scss"; // global css
import "@/assets/styles/ruoyi.scss"; // ruoyi css
import App from "./App";
import store from "./store";
import router from "./router";
import directive from "./directive"; //directive
import { download } from "@/utils/request";
// import './modules/rem'
// import './utils/rem.js'

import "./assets/icons"; // icon
import "./permission"; // permission control
import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import {
  parseTime,
  resetForm,
  addDateRange,
  selectDictLabel,
  selectDictLabels,
  handleTree,
  getMonth,
  getMonth2,
  getQuarterMonth,
  getQuarterMonth2,
  getLastMonth,
  serveGetMonth,
  getCustomizeDay,
} from "@/utils/ruoyi";
import Pagination from "@/components/Pagination";
// 自定义表格工具组件
import RightToolbar from "@/components/RightToolbar";
// 富文本组件
import Editor from "@/components/Editor";
// 文件上传组件
import FileUpload from "@/components/FileUpload";
// 图片上传组件
import ImageUpload from "@/components/ImageUpload";
// 字典标签组件
import DictTag from "@/components/DictTag";
// 头部标签组件
import VueMeta from "vue-meta";

//引入echarts
import echarts from "echarts";
Vue.prototype.$echarts = echarts;

import LbTable from "@/components/table/lb-table/lb-table"; /* 针对element表格封装 */
import LbTableDit from "@/components/table/lb-table/lb-table-dit"; /* 针对element表格封装 */
import RowColTable from "@/components/table/lb-table/row-col"; /* 针对element表格封装 */
import Dialog from "@/components/dialog/index.vue"; /* 弹窗封装 */
import pxDialog from "@/components/dialog/px.vue"; /* 弹窗封装 */
import UserDialog from "@/components/dialog/user.vue"; /* 人员选择 */
import AllDialog from "@/components/dialog/all.vue"; /* 全部 */
import ReportDialog from "@/components/dialog/report.vue"; /* 报表选择 */
import TableHeader from "@/components/table/tableData/header.vue"; /* 表格头部 */
import CommonVxeTable from "@/components/table/vxeTable/components/common.vue";
import MergeVxeTable from "@/components/table/vxeTable/components/merge.vue";
import RowcolTableVxeTable from "@/components/table/vxeTable/components/rowcolTable.vue";
import RowcolTableVxeTableDit from "@/components/table/vxeTable/components/rowcolTableDit.vue";
Vue.component("LbTable", LbTable);
Vue.component("LbTableDit", LbTableDit);
Vue.component("TableHeader", TableHeader);
Vue.component("Dialog", Dialog);
Vue.component("pxDialog", pxDialog);
Vue.component("UserDialog", UserDialog);
Vue.component("AllDialog", AllDialog);
Vue.component("ReportDialog", ReportDialog);
Vue.component("CommonVxeTable", CommonVxeTable);
Vue.component("RowColTable", RowColTable);
Vue.component("MergeVxeTable", MergeVxeTable);
Vue.component("RowcolTableVxeTable", RowcolTableVxeTable);
Vue.component("RowcolTableVxeTableDit", RowcolTableVxeTableDit);

//echarts
import Pie from "@/components/echarts/pie/index.vue"; //普通饼状图
Vue.component("Pie", Pie);
import Rose from "@/components/echarts/pie/rose.vue"; //玫瑰图
Vue.component("Rose", Rose);
import PieGauge from "@/components/echarts/pie/gauge.vue"; //刻度图
Vue.component("PieGauge", PieGauge);
import PieImg from "@/components/echarts/pie/img.vue"; //圆环带图片
Vue.component("PieImg", PieImg);
import Ring from "@/components/echarts/pie/ring.vue"; //环形图
Vue.component("Ring", Ring);
import MoreRing from "@/components/echarts/pie/moreRing.vue"; //多个环形图
Vue.component("MoreRing", MoreRing);
import Water from "@/components/echarts/pie/water.vue"; //水位图
Vue.component("Water", Water);
import Bar from "@/components/echarts/bar/index.vue"; //普通柱状图
Vue.component("Bar", Bar);
import Rank from "@/components/echarts/bar/rank.vue"; //排名
Vue.component("Rank", Rank);
import MoreDirection from "@/components/echarts/bar/moreDirection.vue"; //多个纵向柱状图上下
Vue.component("MoreDirection", MoreDirection);
import MoreDirection2 from "@/components/echarts/bar/moreDirection2.vue"; //多个纵向柱状图上下
Vue.component("MoreDirection2", MoreDirection2);
import MoreColBar from "@/components/echarts/bar/moreCol.vue"; //多个纵向柱状图左右
Vue.component("MoreColBar", MoreColBar);
import RowBar from "@/components/echarts/bar/row.vue"; //横向柱状图
Vue.component("RowBar", RowBar);
import MoreRow from "@/components/echarts/bar/moreRow.vue"; //多个横向柱状图
Vue.component("MoreRow", MoreRow);
import GradualBar from "@/components/echarts/bar/gradual.vue"; //渐变柱状图
Vue.component("GradualBar", GradualBar);
import XRow from "@/components/echarts/bar/xRow.vue"; //横向带X轴柱状图
Vue.component("XRow", XRow);
import ELine from "@/components/echarts/line/index.vue"; //标砖折线图
Vue.component("ELine", ELine);

import Nodata from "@/components/NoData"; /* 引入无数据提示 */
Vue.component("Nodata", Nodata);
import StrokeDetial from "@/components/myComponents/stroke/detail.vue"; /* 容器带详情 */
Vue.component("StrokeDetial", StrokeDetial);
import StrokeTitle from "@/components/myComponents/stroke/title.vue";
Vue.component("StrokeTitle", StrokeTitle);
import StrokeItem from "@/components/myComponents/stroke/item.vue";
Vue.component("StrokeItem", StrokeItem);
import StrokeOrnament from "@/components/myComponents/stroke/ornament.vue"; /* 装饰图 */
Vue.component("StrokeOrnament", StrokeOrnament);
import ChartNum from "@/components/chartNum/index.vue"; /* 翻牌 */
Vue.component("ChartNum", ChartNum);

import json from "@/modules/json.js"; /* 引入公共数据 */
Vue.prototype.json = json;

import rules from "@/modules/rules.js"; /* 引入验证规则 */
Vue.prototype.$rules = rules;
import formatNum from "@/modules/formatNum.js"; /* 数字加逗号 */
Vue.prototype.$formatNum = formatNum;

import utilDialog from "@/components/dialog/index.js"; /* 点击弹出弹出框 */
Vue.prototype.$dialog = utilDialog;

// import print2 from './utils/print';
// Vue.prototype.$print2 = print2;

//element
import ElementSelect from "@/components/element/select/index.vue"; //选择器
Vue.component("ElementSelect", ElementSelect);
import ElementDateSelect from "@/components/element/dateSelect/index.vue"; //日期选择器
Vue.component("ElementDateSelect", ElementDateSelect);
import ElementDateSelectMore from "@/components/element/dateSelect/more.vue"; //日期选择器(自行处理成一个区间)
Vue.component("ElementDateSelectMore", ElementDateSelectMore);
import ElementRadio from "@/components/element/radio/index.vue"; //单选
Vue.component("ElementRadio", ElementRadio);
import ElementRadio3 from "@/components/element/radio/index3.vue"; //单选
Vue.component("ElementRadio3", ElementRadio3);

import AMap from "vue-amap";

// 全局方法挂载
Vue.prototype.getDicts = getDicts;
Vue.prototype.getConfigKey = getConfigKey;
Vue.prototype.parseTime = parseTime;
Vue.prototype.$getMonth = getMonth;
Vue.prototype.$getQuarterMonth2 = getQuarterMonth2;
Vue.prototype.$getQuarterMonth = getQuarterMonth;
Vue.prototype.$getMonth2 = getMonth2;
Vue.prototype.$getLastMonth = getLastMonth;
Vue.prototype.$serveGetMonth = serveGetMonth;
Vue.prototype.$getCustomizeDay = getCustomizeDay;
Vue.prototype.resetForm = resetForm;
Vue.prototype.addDateRange = addDateRange;
Vue.prototype.selectDictLabel = selectDictLabel;
Vue.prototype.selectDictLabels = selectDictLabels;
Vue.prototype.download = download;
Vue.prototype.handleTree = handleTree;

Vue.prototype.msgSuccess = function (msg) {
  this.$message({
    showClose: true,
    message: msg,
    type: "success",
  });
};

Vue.prototype.msgWarning = function (msg) {
  this.$message({
    showClose: true,
    message: msg,
    type: "warning",
  });
};

Vue.prototype.msgError = function (msg) {
  this.$message({
    showClose: true,
    message: msg,
    type: "error",
  });
};

Vue.prototype.msgInfo = function (msg) {
  this.$message.info(msg);
};

Vue.prototype.openLoading = function (val) {
  //相对于body
  const loading = this.$loading({
    // 声明一个loading对象
    lock: false, // 是否锁屏
    text: "正在加载...", // 加载动画的文字
    fullscreen: false,
    spinner: "el-icon-loading", // 引入的loading图标
    background: "rgba(0,0,0,0.8)", // 背景颜色
    body: false,
    customClass: "zIndexLoading", // 遮罩层新增类名
  });
  setTimeout(function () {
    // 设定定时器，超时10S后自动关闭遮罩层，避免请求失败时，遮罩层一直存在的问题
    loading.close(); // 关闭遮罩层
  }, 10000);
  return loading;
};

// 全局组件挂载
Vue.component("DictTag", DictTag);
Vue.component("Pagination", Pagination);
Vue.component("RightToolbar", RightToolbar);
Vue.component("Editor", Editor);
Vue.component("FileUpload", FileUpload);
Vue.component("ImageUpload", ImageUpload);

Vue.use(directive);
Vue.use(VueMeta);
import Print from "./plugins/print/Print";
Vue.use(Print);
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

/**
 * 根据屏幕变化，自动更改 html 的 font-size
 */

function setRem() {
  let clientWidth =
    document.documentElement.clientWidth || document.body.clientWidth;
  let width = clientWidth > 2560 ? 2560 : 1920;
  const htmlWidth = document.body && document.body.offsetWidth;
  const htmlEle = document.getElementsByTagName("html")[0];

  // 默认是在 1920 下 16px，那么对应比例缩放
  htmlEle.style.fontSize = htmlWidth ? (htmlWidth / width) * 16 + "px" : "16px";
}

setRem();

function px2rem(px){
  if(/%/ig.test(px)){ // 有百分号%，特殊处理，表述pc是一个有百分号的数，比如：90%
    return px
  }else{
    return (parseFloat(px) / 192) + 'rem'
  }
}
Vue.prototype.$px2rem = px2rem // 放到全局

// onresize 回调数组
window.resizeCallbackList = [setRem];
window.onresize = () => {
  window.resizeCallbackList.map((callback) => {
    callback();
  });
};

Element.Dialog.props.closeOnClickModal.default = false;

Vue.use(Element, {
  size: Cookies.get("size") || "medium", // set element-ui default size
});
Vue.config.devtools = true;

Vue.config.productionTip = false;

new Vue({
  el: "#app",
  router,
  store,
  render: (h) => h(App),
});
// window.Vue = Vue
